home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / perl / doc / refbase.tex.orig < prev    next >
Encoding:
Text File  |  1991-07-22  |  46.3 KB  |  1,574 lines

  1. % refmaster.tex -- Perl Reference Guide
  2. % SCCS Status     : @(#)@ refmaster    4.1.8
  3. % Author          : Johan Vromans
  4. % Created On      : Wed Jul 10 18:26:19 1991
  5. % Last Modified By: Johan Vromans
  6. % Last Modified On: Mon Jul 15 23:12:27 1991
  7. % Update Count    : 3
  8. % Status          : OK?
  9. %
  10. %%%%%%%%%%%%%%%% Copyright %%%%%%%%%%%%%%%%
  11. %
  12. % The Perl Reference Guide and its associated files are 
  13. %
  14. % Copyright 1989, 1990, 1991 Johan Vromans.
  15. %
  16. % They may be used and reproduced under the terms of the
  17. % GNU Public Licence. A copy of this licence should have 
  18. % been included in your Perl source kit.
  19. %
  20. %%%%%%%%%%%%%%%% Disclaimer %%%%%%%%%%%%%%%%
  21. %
  22. % I'm not a TeX wizard. I stole some of the ideas from 
  23. % Raymond Chen <raymond@math.berkeley.edu> and others.
  24. %
  25. %%%%%%%%%%%%%%%% Start of code %%%%%%%%%%%%%%%%
  26. %
  27. \documentstyle{refbase}
  28.  
  29. \begin{document}
  30.  
  31.  
  32. \begin{titlepage}
  33.  
  34. \hbox{ }
  35. \end{titlepage}
  36.  
  37. \begin{titlepage}
  38.  
  39. \vskip3cm
  40.  
  41. \vbox{{\xviipt\sl Perl Reference Guide}
  42.       {\rule[0.3cm]{\textwidth}{0.25pt}}}
  43.  
  44. {\bf for Perl version 4.010}
  45.  
  46. \vskip1cm
  47. Perl program deigned and created by \\
  48. Larry Wall \<lwall@netlabs.com\>
  49.  
  50. \vskip1cm
  51. Reference guide designed and created by \\
  52. Johan Vromans \<jv@mh.nl\>
  53.  
  54. \vskip1.5cm
  55. \vbox{{\xviipt\sl Contents}
  56.       {\rule[0.3cm]{\textwidth}{0.25pt}}}
  57.  
  58. \newcounter{xx}
  59. \begin{list}{\thexx.}
  60. {\setlength{\topsep}{0pt plus 1pt}
  61.  \setlength{\itemsep}{0pt plus 1pt}
  62.  \setlength{\parsep}{0pt plus 1pt}
  63.  \usecounter{xx}}
  64. \item Command line options
  65. \item Literals
  66. \item Variables
  67. \item Statements
  68. \item Flow control
  69. \item Operators
  70. \item File test operators
  71. \item Arithmetic functions
  72. \item Conversion functions
  73. \item Structure conversion
  74. \item String functions
  75. \item Array and list functions
  76. \item File operations
  77. \item Directory reading routines
  78. \item Input / Output
  79. \item Search and replace functions
  80. \item System interaction
  81. \item Networking
  82. \item SystemV IPC
  83. \item Miscellaneous
  84. \item Formats
  85. \item Info from system files
  86. \item Regular expressions
  87. \item Special variables
  88. \item Special arrays
  89. \item The perl debugger
  90. \end{list}
  91. \vskip1cm
  92. {\catcode`\%=\other \ixpt Rev. \perlrev}
  93. \end{titlepage}
  94.  
  95. \vbox{{\xviipt\sl Conventions}
  96.       {\rule[0.3cm]{\textwidth}{0.25pt}}}
  97.  
  98. \begin{enum}{2cm}
  99. \Xi{|fixed|} denotes literal text.
  100.  
  101. \Xi{<this>} means variable text, i.e. things you must fill in.
  102.  
  103. \Xi{<this>\dag} means that <this> will default to |$_| if omitted.
  104.  
  105. \Xi{\kwd{word}} is a keyword, i.e. a word with a special meaning.
  106.  
  107. \Xi{\fbox{<ret>}} denotes pressing a keyboard key.
  108.  
  109. \Xi{[\ldots]} denotes an optional part.
  110.  
  111. \Xi{(\ldots)*} means that the parentheses may be omitted.
  112.  
  113. \end{enum}
  114. \section{Command line options} 
  115.  
  116. \begin{enum}{1cm}
  117.  
  118. \Xi{|-a|} turns on autosplit mode when used with |-n| or
  119. |-p|. Splits to |@F|.
  120.  
  121. \Xi{|-c|} checks syntax but does not execute.
  122.  
  123. \Xi{|-d|} runs the script under the debugger. Use |-de 0| to
  124. start the debugger without a script.
  125.  
  126. \Xi{|-D| <number>} sets debugging flags. 
  127.  
  128. \Xi{|-e| <commandline>} may be used to enter one line of
  129. script. Multiple |-e| commands may be given to build up a
  130. multi-line script.
  131.  
  132. \Xi{|-i| <ext>} files processed by the |<>| construct are
  133. to be edited in-place.
  134.  
  135. \Xi{|-I| <dir>} with |-P|: tells the C preprocessor where
  136. to look for include files. The directory is prepended to |@INC|.
  137.  
  138. \Xi{|-L| <octnum>} enables automatic line ending processing.
  139.  
  140. \Xi{|-n|} assumes an input loop around your script. Lines are not
  141. printed.
  142.  
  143. \Xi{|-p|} assumes an input loop around your script. Lines are
  144. printed.
  145.  
  146. \Xi{|-P|} runs the C preprocessor on the script before
  147. compilation by perl.
  148.  
  149. \Xi{|-s|} interprets ``|-xxx|'' on the command line as
  150. switches and sets the corresponding variables \$|xxx| in the script.
  151.  
  152. \Xi{|-S|} uses the |PATH| environment variable to search for
  153. the script.
  154.  
  155. \Xi{|-u|} dumps core after compiling the script. To be used with
  156. the {\it undump\/} program (where available).
  157.  
  158. \Xi{|-U|} allows perl to do unsafe operations.
  159.  
  160. \Xi{|-v|} prints the version and patchlevel of your perl
  161. executable.
  162.  
  163. \Xi{|-w|} prints warnings about possible spelling errors and
  164. other error-prone constructs in the script.
  165.  
  166. \Xi{|-x|} extracts perl program from input stream.
  167.  
  168. \Xi{|-0| <val>} (that's the number zero) designates an
  169. initial value for the record terminator \$|/|.
  170. See also |-L|.
  171.  
  172. \end{enum}
  173. \makeuppage
  174. \section{Literals} 
  175.  
  176. Numeric: |123  123.4  5E-10  0xff| (hex)|  0377| (octal).
  177.  
  178. \hangindent=2cm\hangafter=1
  179. String: |'abc'| literal string, no variable interpolation nor
  180. escape characters.
  181. \newline Also: |q/abc/|.
  182. \newline (Almost any pair of delimiters can be used instead of |/.../|.)
  183.  
  184. \hangindent=2cm\hangafter=1
  185. \makebox[1cm]{}|"abc"|
  186. Variables are interpolated and escape sequences are processed. 
  187. \newline Also: |qq/abc/|.
  188. \newline Escape sequences: |\t| (Tab), |\n| (Newline), |\r| (Return),
  189. |\f| (Formfeed), |\b| (Backspace), |\a| (Alarm), |\e|
  190. (Escape), |\033|(octal), |\x1b|(hex), |\c[| (control).
  191. \newline |\l| and |\u| lowcase/upcase the following character; 
  192. \newline |\L| and |\U| lowcase/upcase until a |\E| is encountered.
  193.  
  194.  
  195. \hangindent=2cm\hangafter=1
  196. \makebox[1cm]{}|`|<command>|`|
  197. evaluates to the output of the <command>. 
  198. \newline Also: |qx/|<command>|/|.
  199.  
  200. \hangindent=1cm\hangafter=1
  201. Array: |(1,2,3)|. |()| is an empty array.  
  202. \newline Also: |($a,$b,@rest) = (1,2,...);|
  203. \newline |(1..4)| is the same as |(1,2,3,4)|. Likewise |('abc'..'ade')|
  204.  
  205. \hangindent=1cm\hangafter=1
  206. Associative array:
  207. |(|<key1>|,|<val1>|,|<key2>|,|<val2>|,...)|
  208.  
  209. \hangindent=1cm\hangafter=1
  210. Filehandles: 
  211. \newline Pre-defined: |<STDIN>|, |<STDOUT>|, |<STDERR>|, |<ARGV>|,
  212. |<DATA>|;
  213. \newline User-specified: |<|<handle>|>|, |<$|<var>|>|.
  214. \newline |<>| is the input stream formed by the files specified in
  215. |@ARGV|, or standard input if no arguments are supplied.
  216.  
  217. \hangindent=1cm\hangafter=1
  218. Globs: |<|<pattern>|>| evaluates to all filenames according
  219. to the pattern.
  220. \newline Use |<${|<var>|}>| to glob from a variable.
  221.  
  222. \hangindent=1cm\hangafter=1
  223. Here-Is: |<<|<identifier>
  224. \newline {\it See the manual for details}
  225.  
  226. \hangindent=1cm\hangafter=1
  227. Special tokens:
  228. \newline \_\,\_|FILE|\_\,\_: filename; \_\,\_|LINE|\_\,\_: line number.
  229. \newline \_\,\_|END|\_\,\_: end of program; remaining lines can be read using
  230. \<<data>\>.
  231. \section{Variables} 
  232.  
  233. \begin{enum}{3.2cm}
  234.  
  235. \Xi{|\$var|} a simple scalar variable
  236.  
  237. \Xi{|\$var[28]|} 29th element of array |@var| (the |[]| are
  238. part of it)
  239.  
  240. \Xi{|\$var\{'Feb'\}|} one value from associative array |%var|
  241.  
  242. \Xi{|\$var|} last index of array |@var|
  243.  
  244. \Xi{|@var|} the entire array;
  245.  
  246. in scalar context: the number of elements in the array
  247.  
  248. \Xi{|@var[3,4,5]|} a slice of the array |@var|
  249.  
  250. \Xi{|@var\{'a','b'\}|} a slice of |%var|; same as
  251. |($var{'a'},$var{'b'})|
  252.  
  253. \Xi{|\%var|} the entire associative array
  254.  
  255. \Xi{|\$var\{'a',1,...\}|} emulates a multi-dimensional array
  256.  
  257. \Xi{|('a'..'z')[4,7,9]|} a slice of an array literal
  258.  
  259. \Xi{|*|<name>} refers to all objects represented by <name>.
  260. ``|*name1 = *name2|'' makes |name1| a reference to |name2|.
  261.  
  262. \end{enum}
  263. \section{Statements} 
  264.  
  265. Every statement is an expression, optionally followed by a modifier,
  266. and terminated by a semi-colon.
  267.  
  268. Execution of expressions can depend on other expressions using one of
  269. the modifiers \kwd{if}, \kwd{unless}, \kwd{while} or \kwd{until},
  270. e.g.:
  271.  
  272. \quad    <expr1> \kwd{if} <expr2> |;| \\
  273. \quad    <expr1> \kwd{until} <expr2> |;|
  274.  
  275. Also, by using one of the logical operators \|, |&&| or |? :|, e.g.:
  276.  
  277. \quad    <expr1> \| <expr2> |;| \\
  278. \quad    <expr1> |?| <expr2> |:| <expr3> |;| 
  279.  
  280. Statements can be combined to form a <block> when enclosed in |{}|.
  281.  
  282. Compound statements may be used to control flow:
  283.  
  284. \quad    \kwd{if} |(|<expr>|)| <block> [ [ \kwd{elsif}
  285.     |(|<expr>|)| <BLOCK ...> ] \kwd{else}
  286.     <block> ]
  287. \\
  288. \quad    \kwd{unless} |(|<expr>|)| <block> [ \kwd{else}
  289.     <block> ]
  290. \\
  291. \quad    [ <label>\kwd{:} ] \kwd{while} |(|<expr>|)|
  292.     <block> [ \kwd{continue} <block> ]
  293. \\
  294. \quad    [ <label>\kwd{:} ] \kwd{until} |(|<expr>|)|
  295.     <block> [ \kwd{continue} <block> ]
  296. \\
  297. \quad    [ <label>\kwd{:} ] \kwd{for} |(|<expr>|;|
  298.     <expr>|;| <expr>|)| <block>
  299. \\
  300. \quad    [ <label>\kwd{:} ] \kwd{foreach} <var>\dag
  301.     |(|<array>|)| <block>
  302. \\
  303. \quad    [ <label>\kwd{:} ] <block> [ \kwd{continue} < block> ]
  304.  
  305. Special forms are:
  306.  
  307. \quad    \kwd{do} <block> \kwd{while} <expr> |;| \\
  308. \quad    \kwd{do} <block> \kwd{until} <expr> |;| \\
  309.  
  310. which are guaranteed to perform <block> once before testing <expr>.
  311.  
  312. \section{Flow control} 
  313.  
  314. \begin{enum}{1cm}
  315.  
  316. \Xi{\kwd{do} <block>}
  317. Returns the value of the last command in the sequence of commands indicated by <block>. \kwd{next}, \kwd{last} and \kwd{redo}
  318.  cannot be used here.
  319.  
  320. \Xi{\kwd{do} <subroutine>\kwd{(LIST)}} 
  321. Executes a <subroutine> declared by a \kwd{sub} declaration, and
  322. returns the value of the last expression evaluated in <subroutine> .
  323. \newline Preferred form is: |&|<subroutine> .
  324.  
  325. \Xi{\kwd{do} <FILENAME>}
  326. Executes the contents of <filename> as a perl script. Errors are
  327. returned in |$@|.
  328. \newline Preferred form is: \kwd{require} <filename> .
  329.  
  330. \Xi{\kwd{goto} <label>}
  331. Continue execution at the specified label.
  332.  
  333. \Xi{\kwd{last} [<label>]}
  334. Immediately exits the loop in question. Skips continue block.
  335.  
  336. \Xi{\kwd{next} [<label>]}
  337. Starts the next iteration of the loop.
  338.  
  339. \Xi{\kwd{redo} [<label>]}
  340. Restarts the loop block without evaluating the conditional again.
  341.  
  342. \Xi{\kwd{return} <expr>}
  343. Returns from a subroutine with the value specified.
  344.  
  345. \end{enum}
  346. \section{Operators} 
  347.  
  348. \begin{tabbing}
  349. |    |\=|    |\= \kill
  350. |+ -| \> |* /| \> Addition, subtraction, multiplication, division. \\
  351. |%| \> \> Modulo division. \\
  352. \| \& \> \^ \> Bitwise or, bitwise and, bitwise exclusive or. \\
  353. |>>| \> |<<| \> Bitwise shift right, bitwise shift left. \\
  354. |**| \> \> Exponentiation. \\
  355. |.| \> \> Concatenation of two strings. \\
  356. \kwd{x} \> \> Returns a string or array consisting of the left operand
  357. (an array or \\
  358. \> \> a string) repeated the number of times specified by the right operand.
  359. \end{tabbing}
  360.  
  361. All of the above operators also have an assignment operator, e.g. ``|.=|''.
  362.  
  363. \begin{tabbing}
  364. |    |\=|    |\= \kill
  365. |++| \> |--| \> Auto-increment (magical on strings), auto-decrement. \\
  366. |? :|\>      \> Alternation (if-then-else) operator. \\
  367. \|   \> \&   \> Logical or, logical and. \\
  368. |=|\,|=| \> |!=| \> Numeric equality, inequality. \\
  369. \kwd{eq} \> \kwd{ne} \> String equality, inequality. \\
  370. |<|  \>  |>|  \> Numeric less than, greater than. \\
  371. \kwd{lt} \> \kwd{gt} \> String less than, greater than. \\
  372. |<=| \> |>=| \> Numeric less (greater) than or equal to. \\
  373. \kwd{le} \> \kwd{ge} \> String less (greater) than or equal. \\
  374. |<=>| \> \> Numeric compare. Returns -1, 0 or 1. \\
  375. \kwd{cmp} \> \> String compare. Returns -1, 0 or 1. \\
  376. |=~| \> |!~| \> Search pattern, substitution, or translation (negated). \\
  377. |..| \> \> Enumeration, also input line range operator. \\
  378. |,| \> \> Comma operator.
  379. \end{tabbing}
  380. \section{File test operators} 
  381.  
  382. These unary operators takes one argument, either a filename or a
  383. filehandle, and tests the associated file to see if something is true
  384. about it. If the argument is omitted, tests |$_| (except for |-t,|
  385. which tests |STDIN|). If the special argument |_| (underscore) is
  386. passed, uses the info of the preceding test. 
  387.  
  388. \begin{enum}{2.5cm}
  389.  
  390. \Xi{|-r -w -x -o|}  File is readable/writable/executable/owned by
  391. effective uid. 
  392.  
  393. \Xi{|-R -W -X -O|}  File is readable/writable/executable/owned by real
  394. uid.  
  395.  
  396. \Xi{|-e  -z  -s|}  File exists / has zero/non-zero size. 
  397.  
  398. \Xi{|-f  -d|}  File is a plain file, a directory.
  399.  
  400. \Xi{|-l  -S  -p|}  File is a symbolic link, a socket, a named pipe (FIFO). 
  401.  
  402. \Xi{|-b  -c|}  File is a block/character special file. 
  403.  
  404. \Xi{|-u  -g  -k|}  File has setuid/setgid/sticky bit set. 
  405.  
  406. \Xi{|-t|}  Tests if filehandle (|STDIN| by default) is opened to a tty.
  407.  
  408. \Xi{|-T  -B|}  File is a text/non-text (binary) file.  |-T| and |-B|
  409. return TRUE on a null file, or a file at EOF when testing a filehandle. 
  410.  
  411. \Xi{|-M  -A  -C|}  File creation / access / inode change time. Measured
  412. in days since this program started. See also |$^T| in section
  413. ``Special~Variables''.
  414.  
  415. \end{enum}
  416. \makeuppage
  417. A <list> is a (possibly parenthesised) list of expressions, variables
  418. or <list>s. An array variable or an array slice may always be used
  419. instead of a <list>.  
  420.  
  421. \section{Arithmetic functions} 
  422.  
  423. \begin{enum}{1cm}
  424.  
  425. \Xi{\kwd{atan2(}<y>\kwd{,}<x>\kwd{)}}
  426. Returns the arctangent of <Y>/<X> in the range -$\pi$ to $\pi$.
  427.  
  428. \Xi{\kwd{cos(}\oEXPR \kwd{)}*}
  429. Returns the cosine of <expr> (expressed in radians).
  430.  
  431. \Xi{\kwd{exp(}\oEXPR \kwd{)}*}
  432. Returns |e| to the power of <expr>.
  433.  
  434. \Xi{\kwd{int(}\oEXPR \kwd{)}*}
  435. Returns the integer portion of <expr>.
  436.  
  437. \Xi{\kwd{log(}\oEXPR \kwd{)}*}
  438. Returns natural logarithm (base |e|) of <expr>.
  439.  
  440. \Xi{\kwd{rand}[\kwd{(}<expr>\kwd{)}*]}
  441. Returns a random fractional number between 0 and the value of <expr>.
  442. If <expr> is omitted, returns a value between 0 and 1. 
  443.  
  444. \Xi{\kwd{sin(}\oEXPR \kwd{)}*}
  445. Returns the sine of <expr> (expressed in radians).
  446.  
  447. \Xi{\kwd{sqrt(}\oEXPR \kwd{)}*}
  448. Return the square root of <expr>.
  449.  
  450. \Xi{\kwd{srand}[\kwd{(}<expr>\kwd{)}*]}
  451. Sets the random number seed for the rand operator.
  452.  
  453. \Xi{\kwd{time}}
  454. Returns the number of seconds since January 1, 1970. Suitable for
  455. feeding to \kwd{gmtime} and \kwd{localtime}. 
  456.  
  457. \end{enum}
  458. \section{Conversion functions} 
  459.  
  460. \begin{enum}{1cm}
  461.  
  462. \Xi{\kwd{gmtime(}<expr>\kwd{)}*}
  463. Converts a time as returned by the \kwd{time} function to a 9-element
  464. array (\$sec, \$min, \$hour, \$mday, \$mon, \$year, \$wday,
  465. \$yday, \$isdst) with the time analyzed for the Greenwich timezone.
  466. \$mon has the range 0..11 and \$wday has the range 0..6.
  467.  
  468. \Xi{\kwd{hex(}\oEXPR\kwd{)}*}
  469. Returns the decimal value of <expr> interpreted as an hex string.
  470.  
  471. \Xi{\kwd{localtime(}<expr>\kwd{)}*}
  472. Converts a time as returned by the \kwd{time} function to a 9-element
  473. array with the time analyzed for the local timezone. 
  474.  
  475. \Xi{\kwd{oct(}\oEXPR\kwd{)}*}
  476. Returns the decimal value of <expr> interpreted as an octal string. If
  477. <expr> starts off with |0x|, interprets it as a hex string instead.
  478.  
  479. \Xi{\kwd{ord(}\oEXPR\kwd{)}*}
  480. Returns the ascii value of the first character of <expr>.
  481.  
  482. \Xi{\kwd{vec(}<expr>\kwd{,}<offset>\kwd{,}<bits>\kwd{)}}
  483. Treats <expr> as a string of unsigned ints, and yields the bit at
  484. <offset>. <bits> must be between 1 and 32. May be used as an lvalue.
  485.  
  486. \end{enum}
  487. \section{Structure conversion} 
  488.  
  489. \begin{enum}{1cm}
  490.  
  491. \Xi{\kwd{pack(}<template>\kwd{,}<list>\kwd{)}}
  492. Packs the values into a binary structure using <template>.
  493.  
  494. \Xi{\kwd{unpack(}<template>\kwd{,}<expr>\kwd{)}}
  495. Unpacks the structure <expr> into an array, using <template>.
  496.  
  497. <template> is a sequence of characters as follows:
  498.  
  499. \begin{tabbing}
  500. |  |\=|a |\=|/ |\=|A  |\= \kill
  501.   \> |a| \> / \> |A| \> Ascii string, null / space padded \\
  502.   \> |b| \> / \> |B| \> Bit string in ascending / descending order \\
  503.   \> |c| \> / \> |C| \> Native / unsigned char value \\
  504.   \> |f| \> / \> |d| \> Single / double float in native format \\
  505.   \> |h| \> / \> |H| \> Hex string, low / high nybble first. \\
  506.   \> |i| \> / \> |I| \> Signed / unsigned integer value \\
  507.   \> |l| \> / \> |L| \> Signed / unsigned long value \\
  508.   \> |n| \> / \> |N| \> Short / long in network byte order \\
  509.   \> |s| \> / \> |S| \> Signed / unsigned short value \\
  510.   \> |u| \> / \> |p| \> Uuencoded string / Pointer to a string \\
  511.   \> |x| \> / \> |@| \> Null byte / null fill until position \\
  512.   \> |X| \>   \>     \> Backup a byte
  513. \end{tabbing}
  514.  
  515. Each character may be followed by a decimal number which will be used
  516. as a repeat count, an |*| specifies all remaining arguments. \\
  517. If the format is preceded with |%|<n>, \kwd{unpack} returns an
  518. <n>-bit checksum instead. \\
  519. Spaces may be included in the template for readability purposes.
  520.  
  521. \end{enum}
  522. \section{String functions} 
  523.  
  524. \begin{enum}{1cm}
  525.  
  526. \Xi{\kwd{chop(}<list>\dag\kwd{)}}
  527. Chops off the last character on all elements of the list; returns the
  528. last chopped character. The parentheses may be omitted if <list> is a
  529. single variable.
  530.  
  531. \Xi{\kwd{crypt(}<plaintext>\kwd{,}<salt>\kwd{)}}
  532. Encrypts a string.
  533.  
  534. \Xi{\kwd{eval(}\oEXPR \kwd{)}*}
  535. <expr> is parsed and executed as if it were a perl program. The value
  536. returned is the value of the last expression evaluated. If there is a
  537. syntax error or runtime error, an undefined string is returned by
  538. eval, and |$@| is set to the error message.
  539.  
  540. \Xi{\kwd{index(}<str>\kwd{,}<substr>[\kwd{,}<offset>]\kwd{)}}
  541. Returns the position of <substr> in <str> at or after <offset>. If the
  542. substring is not found, returns |$[-1|.
  543.  
  544. \Xi{\kwd{length(}\oEXPR\kwd{)}*}
  545. Returns the length in characters of the value of <expr>.
  546.  
  547. \Xi{\kwd{rindex(}<str>\kwd{,}<substr>[\kwd{,}<offset>]\kwd{)}}
  548. Returns the position of the last occurrence of <substr> in <str> at or
  549. before <offset>.
  550.  
  551. \Xi{\kwd{substr(}<expr>\kwd{,}<offset>[\kwd{,}<len>]\kwd{)}}
  552. Extracts a substring out of <expr> and returns it. If <offset>
  553. is negative, counts from the end of the string. May be used as an lvalue.
  554.  
  555. \end{enum}
  556. \section{Array and list functions} 
  557.  
  558. \begin{enum}{1cm}
  559.  
  560. \Xi{\kwd{delete} \$<array>\{<key>\}}
  561. Deletes the specified value from the specified associative array.
  562. Returns the deleted value. 
  563.  
  564. \Xi{\kwd{each(}|\%|<array>\kwd{)}*}
  565. Returns a 2-element array consisting of the key and value for the next
  566. value of an associative array. Entries are returned in an apparently
  567. random order. When the array is entirely read, a null array is
  568. returned. The next call to \kwd{each} after that will start iterating again.
  569.  
  570. \Xi{\kwd{grep(}<expr>\kwd{,}<list>\kwd{)}}
  571. Evaluates <expr> for each element of the <list>, locally setting |$_|
  572. to refer to the element. Modifying |$_| will modify the corresponding
  573. element from <list>. Returns array of elements from <list> for which
  574. <expr> returned true. 
  575.  
  576. \Xi{\kwd{join(}<expr>\kwd{,}<list>\kwd{)}}
  577. Joins the separate strings of <list> into a single string with fields
  578. separated by the value of <expr>, and returns the string.
  579.  
  580. \Xi{\kwd{keys(}|\%|<array>\kwd{)}*}
  581. Returns an array with of all the keys of the named
  582. associative array.
  583.  
  584. \Xi{\kwd{pop(}|@|<array>\kwd{)}*}
  585. Pops and returns the last value of the array, shortens the array by 1. 
  586.  
  587. \Xi{\kwd{push(}|@|<array>\kwd{,}<list>\kwd{)}}
  588. Pushes the values of <list> onto the end of <array>. The length of the
  589. array increases by the length of <list>.
  590.  
  591. \Xi{\kwd{reverse(}<list>\kwd{)}*}
  592. In array context: returns the <list> in reverse order. \\
  593. In scalar
  594. context: returns the first element of <list> with bytes reversed. 
  595.  
  596. \Xi{\kwd{shift}[\kwd{(}|@|<array>\kwd{)}*]}
  597. Shifts the first value of the array off and returns it, shortening the
  598. array by 1 and moving everything down. If |@|<array> is omitted, shifts
  599. |@ARGV| in main and |@_| in subroutines.  
  600.  
  601. \Xi{\kwd{sort(} [<subroutine> ] <list>\kwd{)}*}
  602. Sorts the <list> and returns the sorted array value. If <subroutine>
  603. is specified, gives the name of a subroutine that returns less than
  604. zero, zero, or greater than zero, depending on how the elements of the
  605. array, available to the routine as |$a| and |$b|, are to be ordered.
  606.  
  607. \Xi{\kwd{splice(}|@|<array>\kwd{,}<offset>[\kwd{,}<length>[\kwd{,}<list>]]\kwd{)}}
  608. Removes the elements of |@|<array> designated by <offset> and
  609. <length>, and replaces them with <list> (if specified). \\
  610. Returns the elements removed.
  611.  
  612. \Xi{\kwd{split}[\kwd{(}<pattern>[\kwd{,}\oEXPR [\kwd{,}<limit>]]\kwd{)}]}
  613. Splits a string into an array of strings, and returns it. If <limit>
  614. is specified, splits in no more than that many fields. If <pattern> is
  615. also omitted, splits on whitespace. If
  616. not in array context: returns number of fields and splits to |@_|.
  617. See also: ``Search and Replace Functions''. 
  618.  
  619. \Xi{\kwd{unshift(}|@|<array>\kwd{,}<list>\kwd{)}}
  620. Prepends list to the front of the array, and returns the number of
  621. elements in the new array.
  622.  
  623. \Xi{\kwd{values(}|\%|<array>\kwd{)}*}
  624. Returns a normal array consisting of all the values of the named
  625. associative array. 
  626.  
  627. \end{enum}
  628.  
  629.  
  630. \section{File operations} 
  631.  
  632. Functions operating on a list of files return the number of files
  633. successfully operated upon.
  634.  
  635. \begin{enum}{1cm}
  636.  
  637. \Xi{\kwd{chmod(}<list>\kwd{)}*}
  638. Changes the permissions of a list of files. The first element of the
  639. list must be the numerical mode. 
  640.  
  641. \Xi{\kwd{chown(}<list>\kwd{)}*}
  642. Changes the owner and group of a list of files. The first two elements
  643. of the list must be the numerical uid and gid. 
  644.  
  645. \Xi{\kwd{truncate(}<file>\kwd{,}<size>\kwd{)}}
  646. truncates <file> to <size>. <file> may be a filename or a filehandle.
  647.  
  648. \Xi{\kwd{link(}<oldfile>\kwd{,}<newfile>\kwd{)}}
  649. Creates a new filename linked to the old filename.
  650.  
  651. \Xi{\kwd{lstat(}<file>\kwd{)}}
  652. Like stat, but does not traverse a final symbolic link.
  653.  
  654. \Xi{\kwd{mkdir(}<dir>\kwd{,}<mode>\kwd{)}}
  655. Creates a directory with given permissions. Sets |$!| on failure.
  656.  
  657. \Xi{\kwd{select(}<rbits>\kwd{,}<wbits>\kwd{,}<nbits>\kwd{,}<timeout>\kwd{)}}
  658. Performs a {\it select\/}(2) system call with the same parameters.
  659.  
  660. \Xi{\kwd{readlink(}\oEXPR\kwd{)}*}
  661. Returns the value of a symbolic link.
  662.  
  663. \Xi{\kwd{rename(}<oldname>\kwd{,}<newname>\kwd{)}}
  664. Changes the name of a file.
  665.  
  666. \Xi{\kwd{rmdir(}<filename>\dag\kwd{)}*}
  667. Deletes the directory if it is empty. Sets |$!| on failure.
  668.  
  669. \Xi{\kwd{stat(}<file>\kwd{)}}
  670. Returns a 13-element array (\$dev, \$ino, \$mode, \$nlink, \$uid, \$gid,
  671. \$rdev, \$size, \$atime, \$mtime, \$ctime, \$blksize, \$blocks). <file> can
  672. be a filehandle, an expression evaluating to a filename, or |_| to
  673. refer to the last file test operation. 
  674.  
  675. \Xi{\kwd{symlink(}<oldfile>\kwd{,}<newfile>\kwd{)}}
  676. Creates a new filename symbolically linked to the old filename.
  677.  
  678. \Xi{\kwd{unlink(}<list>\kwd{)}*}
  679. Deletes a list of files.
  680.  
  681. \Xi{\kwd{utime(}<list>\kwd{)}*}
  682. Changes the access and modification times. The first two elements of
  683. the list must be the numerical access and modification times.
  684.  
  685. \end{enum}
  686.  
  687.  
  688. \makeuppage
  689. \section{Directory reading routines} 
  690.  
  691. \begin{enum}{1cm}
  692.  
  693. \Xi{\kwd{closedir(}<dirhandle>\kwd{)}*}
  694. Closes a directory opened by opendir.
  695.  
  696. \Xi{\kwd{opendir(}<dirhandle>\kwd{,}<dirname>\kwd{)}}
  697. Opens a directory on the handle specified.
  698.  
  699. \Xi{\kwd{readdir(}<dirhandle>\kwd{)}*}
  700. Returns the next entry (or an array of entries) in the directory.
  701.  
  702. \Xi{\kwd{rewinddir(}<dirhandle>\kwd{)}*}
  703. Positions the directory to the beginning.
  704.  
  705. \Xi{\kwd{seekdir(}<dirhandle>\kwd{,}<pos>\kwd{)}}
  706. Sets position for readdir on the directory.
  707.  
  708. \Xi{\kwd{telldir(}<dirhandle>\kwd{)}*}
  709. Returns the postion in the directory.
  710.  
  711. \end{enum}
  712. \section{Input / Output} 
  713.  
  714. In input/output operations, <filehandle> may be a filehandle as opened
  715. by the \kwd{open} operator, or a scalar variable which evaluates to
  716. the name of a filehandle to be used.  
  717.  
  718. \begin{enum}{1cm}
  719.  
  720. \Xi{\kwd{binmode(}<filehandle>\kwd{)}*}
  721. Arranges for the file opened on <filehandle> to be read in ``binary''
  722. mode as opposed to ``text'' mode (MS-DOS only). 
  723.  
  724. \Xi{\kwd{close(}<filehandle>\kwd{)}*}
  725. Closes the file or pipe associated with the file handle.
  726.  
  727. \Xi{\kwd{dbmclose(}|\%|<array>\kwd{)}*}
  728. Breaks the binding between the array and the dbm file.
  729.  
  730. \Xi{\kwd{dbmopen(}|\%|<array>\kwd{,}<dbmname>\kwd{, }<mode>\kwd{)}}
  731. Binds a dbm or ndbm file to the associative array. If the database
  732. does not exist, it is created with the indicated mode. 
  733.  
  734. \Xi{\kwd{eof(}<filehandle>\kwd{)}}
  735. Returns 1 if the next read will return end of file, or if the file is
  736. not open. 
  737.  
  738. \Xi{\kwd{eof}}
  739. Returns the eof status for the last file read.
  740.  
  741. \Xi{\kwd{eof( )}}
  742. Indicates eof on the pseudo file formed of the files listed on the
  743. command line. 
  744.  
  745. \Xi{\kwd{fcntl(}<filehandle>\kwd{,}<function>\kwd{,}|\$|<var>\kwd{)}}
  746. Implements the {\it fcntl\/}(2) function. This function has non-standard
  747. return values. See the manual for details. 
  748.  
  749. \Xi{\kwd{fileno(}<filehandle>\kwd{)}*}
  750. Returns the file descriptor for a given (open) file.
  751.  
  752. \Xi{\kwd{flock(}<filehandle>\kwd{,}<operation>\kwd{)}}
  753. Calls {\it flock\/}(2) on the file. <operation> adds from 1 (shared), 2
  754. (exclusive), 4 (non-blocking) or 8 (unlock). 
  755.  
  756.  
  757. \Xi{\kwd{getc}[\kwd{(}<filehandle>\kwd{)}*]}
  758. Yields the next character from the file, or |""| on EOF. If
  759. <filehandle> is omitted, reads from |STDIN|. 
  760.  
  761. \Xi{\kwd{ioctl(}<filehandle>\kwd{,}<function>\kwd{,}|\$|<var>\kwd{)}}
  762. performs {\it ioctl}(2) on the file. This function has non-standard
  763. return values. See the manual for details. 
  764.  
  765. \Xi{\kwd{open(}<filehandle>[\kwd{,}<filename>]\kwd{)}}
  766. Opens a file and associates it with <filehandle>. If <filename> is
  767. omitted, the scalar variable of the same name as the <filehandle> must
  768. contain the filename.
  769.  
  770. The following filename conventions apply when opening a file.
  771.  
  772. \begin{enum}{2cm}
  773. \Xi{|"|<file>|"|} open <file> for input. Also |"<|<file>|"|.
  774.  
  775. \Xi{|">|<file>|"|} open <file> for output, creating it if necessary.
  776.  
  777. \Xi{|">>|<file>|"|} open <file> in append mode.
  778.  
  779. \Xi{|"+>|<file>|"|} open <file> with read/write access.
  780.  
  781. \Xi{|"\||<cmd>|"|} opens a pipe to command <cmd>.
  782.  
  783. \Xi{|"|<cmd>|\|"|} opens a pipe from command <cmd>.
  784. \end{enum}
  785.  
  786. <file> may be |&|<filehnd> in which case the new file handle is
  787. connected to the (previously opened) filehandle <filehnd>.
  788.  
  789. \kwd{open} 
  790. returns 1 upon success, \kwd{undef} otherwise, except for pipes. The
  791. parentheses may be omitted, if only a <filehandle> is specified.
  792.  
  793. \Xi{\kwd{pipe(}<readhandle>\kwd{,}<writehandle>\kwd{)}}
  794. Returns a pair of connected pipes.
  795.  
  796. \Xi{\kwd{print}[\kwd{(}[<filehandle>]<list>\dag\kwd{)}*]}
  797. Prints a string or a comma-separated list of strings. If <filehandle>
  798. is omitted, prints by default to standard output (or to the last
  799. selected output channel - see \kwd{select}).  
  800.  
  801. \Xi{\kwd{printf}[\kwd{(}[<filehandle>] <list>\kwd{)}*]}
  802. Equivalent to \kwd{print} <filehandle> \kwd {sprintf(}<list>\kwd{)}.
  803.  
  804. \Xi{\kwd{read(}<filehandle>\kwd{,}|\$|<var>\kwd{,}<length>[\kwd{,}<offset>]\kwd{)}}
  805. Read <length> binary bytes from the file into the variable at
  806. <offset>. Returns number of bytes actually read. 
  807.  
  808. \Xi{\kwd{seek(}<filehandle>\kwd{,}<position>\kwd{,}<whence>\kwd{)}}
  809. Arbitrarily positions the file. Returns 1 upon success, 0 otherwise.
  810.  
  811. \Xi{\kwd{select}[\kwd{(}<filehandle>\kwd{)}}
  812. Sets the current default filehandle for output operations. Returns the
  813. previously selected filehandle. 
  814.  
  815. \Xi{\kwd{sprintf(}<format>\kwd{,}<list>\kwd{)}}
  816. Returns a string formatted by (almost all of) the usual printf
  817. conventions. 
  818.  
  819. \Xi{\kwd{sysread(}<filehandle>\kwd{,}|\$|<var>\kwd{,}<length>[\kwd{,}<offset>]\kwd{)}}
  820. Reads <length> bytes into |$|<var> at <offset>.
  821.  
  822. \Xi{\kwd{syswrite(}<filehandle>\kwd{,}<scalar>\kwd{,}<length>[\kwd{,}<offset>]\kwd{)}}
  823. Writes <length> bytes from <scalar> at <offset>.
  824.  
  825. \Xi{\kwd{tell}[\kwd{(}<filehandle>\kwd{)}]*}
  826. Returns the current file position for the file. If <filehandle> is
  827. omitted, assumes the file last read. 
  828.  
  829. \Xi{\kwd{write}[\kwd{(}<filehandle>\kwd{)}]*}
  830. Writes a formatted record to the specified file, using the format
  831. associated with that file. See ``Formats''. 
  832.  
  833. \end{enum}
  834. \makeuppage
  835. \section{Search and replace functions}
  836.  
  837. \begin{enum}{1cm}
  838.  
  839. \catcode`\~=\other
  840.  
  841. \Xi{[<expr> |=~|] [\kwd{m}]|/|<pattern>|/|[\kwd{g}][\kwd{i}][\kwd{o}]}
  842. Searches <expr> (default: |$_|) for a pattern. If you prepend an
  843. \kwd{m} you can use almost any pair of characters as delimiters. If
  844. used in array context, an array is returned consisting of the
  845. subexpressions matched by the parentheses in pattern, i.e.
  846. |($1,$2,$3,...)|.
  847. \\
  848. Optional modifiers: \kwd{g} matches as many times as possible; \kwd{i}
  849. searches in a case-insensitive manner; \kwd{o} interpolates variables
  850. only once.
  851. \\
  852. If <pattern> is empty, the most recent pattern from a
  853. previous match or replacement is used.
  854. \\
  855. With \kwd{g} the match can be used as an iterator in scalar context.
  856.  
  857. \Xi{|?|<pattern>|?|}
  858. This is just like the |/|<pattern>|/| search, except that it matches
  859. only once between calls to the reset operator. If <pattern> is empty,
  860. the most recent pattern from a previous match or replacement is used.
  861.  
  862. \Xi{[|\$|<var> |=~|] \kwd{s}|/|<pattern>|/|<replacement>|/|[\kwd{g}][\kwd{i}][\kwd{e}][\kwd{o}]}
  863. Searches a string for a pattern, and if found, replaces that pattern
  864. with the replacement text and returns the number of substitutions
  865. made. Otherwise it returns false. 
  866. \\
  867. Optional modifiers: \kwd{g} replaces all occurrences of the pattern;
  868. \kwd{e} interprets the replacement string as an expression; \kwd{i}
  869. and \kwd{o} as with |/|<pattern>|/| matching. Almost any delimiter may
  870. replace the slashes; if single quotes are used, no interpretation is
  871. done on the replacement string.
  872. \\
  873. If <pattern> is empty, the most recent pattern from a previous match or replacement is used.
  874.  
  875. \Xi{\kwd{study}[\kwd{(}|\$|<var>\dag\kwd{)}*]}
  876. Study the contents of |$|<var> in anticipation of doing many pattern
  877. matches on the contents before it is next modified.
  878.  
  879. \Xi{[|\$|<var> |=~|] \kwd{tr}|/|<searchlist>|/|<replacementlist>|/|[\kwd{c}][\kwd{d}][\kwd{s}]}
  880. Translates all occurrences of the characters found in the search list
  881. with the corresponding character in the replacement list. It returns
  882. the number of characters replaced. \kwd{y} may be used instead of \kwd{tr}. 
  883. \\
  884. Optional modifiers: \kwd{c} complements the <searchlist>; \kwd{d}
  885. deletes all characters not found in <searchlist>; \kwd{s} squeezes all
  886. sequences of characters that are translated into the same target
  887. character into one occurrence of this character.
  888.  
  889. \end{enum}
  890. \section{System interaction} 
  891.  
  892. \begin{enum}{1cm}
  893.  
  894. \Xi{\kwd{alarm(}<expr>\kwd{)}*}
  895. Schedules a |SIGALRM| to be delivered after <expr> seconds. 
  896.  
  897. \Xi{\kwd{chdir} [\kwd{(}<expr>\kwd{)}*]}
  898. Changes the working directory, |$ENV{"HOME"}| if <expr> is omitted.
  899.  
  900. \Xi{\kwd{chroot(}<filename>\dag\kwd{)}*}
  901. Changes the root directory for the process and its children.
  902.  
  903. \Xi{\kwd{die}[\kwd{(}<list>\kwd{)}*]}
  904. Prints the value of <list> to |STDERR| and exits with the current
  905. value of |$!| (errno). If |$!| is 0, exits with the value of |($? >> 8)|.
  906. If |($? >> 8)| is 0, exits with 255. <list> defaults to
  907. |"Died."|.
  908.  
  909. \Xi{\kwd{exec(}<list>\kwd{)}*}
  910. Executes the system command in <list>; does not return.
  911.  
  912. \Xi{\kwd{exit(}<expr>\kwd{)}*}
  913. Exits immediately with the value of |EXPR|.
  914.  
  915. \Xi{\kwd{fork}}
  916. Does a {\it fork\/}(2) system call. Returns the child pid to the parent
  917. process and zero to the child process. 
  918.  
  919. \Xi{\kwd{getlogin}}
  920. Returns the current login name as known by the system.
  921.  
  922. \Xi{\kwd{getpgrp}[\kwd{(}<pid>\kwd{)}*]}
  923. Returns the process group for process <pid> (0, or omitted,  means the
  924. current process). 
  925.  
  926. \Xi{\kwd{getppid}}
  927. Returns the process id of the parent process.
  928.  
  929. \Xi{\kwd{getpriority(}<which>\kwd{,}<who>\kwd{)}}
  930. Returns the current priority for a process, process group, or user.
  931.  
  932. \Xi{\kwd{kill(}<list>\kwd{)}*}
  933. Sends a signal to a list of processes. The first element of the list
  934. must be the signal to send (numeric, or its name as a string). 
  935.  
  936. \Xi{\kwd{setpgrp(}<pid>\kwd{,}<pgrp>\kwd{)}}
  937. Sets the process group for the <pid> (0 = current process).
  938.  
  939. \Xi{\kwd{setpriority(}<which>\kwd{,}<who>\kwd{,}<prio>\kwd{)}}
  940. Sets the current priority for a process, process group, or a user.
  941.  
  942. \Xi{\kwd{sleep}[\kwd{(}<expr>\kwd{)}*]}
  943. Causes the script to sleep for <expr> seconds, or forever if no
  944. <expr>. Returns the number of seconds actually slept. 
  945.  
  946. \Xi{\kwd{syscall(}<list>\kwd{)}*}
  947. Calls the system call specified in the first element of the list,
  948. passing the rest of the list as arguments to the call. 
  949.  
  950. \Xi{\kwd{system(}<list>\kwd{)}*}
  951. Does exactly the same thing as \kwd{exec }<list> except that a fork is
  952. done first, and the parent process waits for the child process to complete. 
  953.  
  954. \Xi{\kwd{times}}
  955. Returns a 4-element array (\$user, \$system, \$cuser, \$csystem) giving
  956. the user and system times, in seconds, for this process and the
  957. children of this process.  
  958.  
  959. \Xi{\kwd{umask}[\kwd{(}<expr>\kwd{)}*]}
  960. Sets the umask for the process and returns the old one. If <expr> is
  961. omitted, returns current umask value. 
  962.  
  963. \Xi{\kwd{wait}}
  964. Waits for a child process to terminate and returns the pid of the
  965. deceased process (-1 if none). The status is returned in |$?|. 
  966.  
  967. \Xi{\kwd{waitpid(}<pid>\kwd{,}<flags>\kwd{)}}
  968. Performs the same function as the corresponding system call.
  969.  
  970. \Xi{\kwd{warn(}<list>\kwd{)}*}
  971. Prints the message on |STDERR| like \kwd{die}, but doesn't exit.
  972.  
  973. \end{enum}
  974. \makeuppage
  975. \section{Networking} 
  976.  
  977. \begin{enum}{1cm}
  978.  
  979. \Xi{\kwd{accept(}<newsocket>\kwd{,}<genericsocket>\kwd{)}}
  980. Accepts a new socket.
  981.  
  982. \Xi{\kwd{bind(}<socket>\kwd{,}<name>\kwd{)}}
  983. Binds the <name> to the <socket>.
  984.  
  985. \Xi{\kwd{connect(}<socket>\kwd{,}<name>\kwd{)}}
  986. Connects the <name> to the <socket>.
  987.  
  988. \Xi{\kwd{getpeername(}<socket>\kwd{)}}
  989. Returns the socket address of the other end of the <socket>.
  990.  
  991. \Xi{\kwd{getsockname(}<socket>\kwd{)}}
  992. Returns the name of the socket.
  993.  
  994. \Xi{\kwd{getsockopt(}<socket>\kwd{,}<level>\kwd{,}<optname>\kwd{)}}
  995. Returns the socket options.
  996.  
  997. \Xi{\kwd{listen(}<socket>\kwd{,}<queuesize>\kwd{)}}
  998. Starts listening on the specified <socket>.
  999.  
  1000. \Xi{\kwd{recv(}<socket>\kwd{,}<scalar>\kwd{,}<length>\kwd{,}<flags>\kwd{)}}
  1001. Receives a message on <socket>.
  1002.  
  1003. \Xi{\kwd{send(}<socket>\kwd{,}<msg>\kwd{,}<FLAGS[>\kwd{,}<to>]\kwd{)}}
  1004. Sends a message on the <socket>.
  1005.  
  1006. \Xi{\kwd{setsockopt(}<socket>\kwd{,}<level>\kwd{,}<optname>\kwd{,}<optval>\kwd{)}}
  1007. Sets the requested socket option.
  1008.  
  1009. \Xi{\kwd{shutdown(}<socket>\kwd{,}<how>\kwd{)}}
  1010. Shuts down a <socket>.
  1011.  
  1012. \Xi{\kwd{socket(}<socket>\kwd{,}<domain>\kwd{,}<type>\kwd{,}<protocol>\kwd{)}}
  1013. Creates a <socket> in <domain> with <type> and <protocol>.
  1014.  
  1015. \Xi{\kwd{socketpair(}<socket1>\kwd{,}<socket2>\kwd{,}<domain>\kwd{,}<type>\kwd{,}<protocol>\kwd{)}}
  1016. As socket, but creates a pair of bi-directional sockets.
  1017.  
  1018. \end{enum}
  1019. \section{SystemV IPC} 
  1020.  
  1021. The following functions all perform the same action as the
  1022. corresponding system calls.
  1023.  
  1024. \kwd{msgctl(}<id>\kwd{,}<cmd>\kwd{,}<args>\kwd{)} \\
  1025. \kwd{msgget(}<key>\kwd{,}<flags>\kwd{)} \\
  1026. \kwd{msgsnd(}<id>\kwd{,}<msg>\kwd{,}<flags>\kwd{)} \\
  1027. \kwd{msgrcv(}<id>\kwd{,}\$<var>\kwd{,}<size>\kwd{,}<type>\kwd{,}<flags>\kwd{)} \\
  1028. \kwd{semctl(}<id>\kwd{,}<semnum>\kwd{,}<cmd>\kwd{,}<arg>\kwd{)} \\
  1029. \kwd{semget(}<key>\kwd{,}<nsems>\kwd{,}<size>\kwd{,}<flags>\kwd{)} \\
  1030. \kwd{semop(}<key>\kwd{,}...\kwd{)} \\
  1031. \kwd{shmctl(}<id>\kwd{,}<cmd>\kwd{,}<arg>\kwd{)} \\
  1032. \kwd{shmget(}<key>\kwd{,}<size>\kwd{,}<flags>\kwd{)} \\
  1033. \kwd{shmread(}<id>\kwd{,}\$<var>\kwd{,}<pos>\kwd{,}<size>\kwd{)} \\
  1034. \kwd{shmwrite(}<id>\kwd{,}<string>\kwd{,}<pos>\kwd{,}<size>\kwd{)}
  1035. \makeuppage
  1036. \section{Miscellaneous} 
  1037.  
  1038. \begin{enum}{1cm}
  1039.  
  1040. \Xi{\kwd{caller}[\kwd{(}<expr>\kwd{)}]}
  1041. Returns an array (\$package,\$file,\$line,...) for a specific subroutine
  1042. call. ``|caller|'' returns this info for the current subroutine,
  1043. ``|caller(1)|'' for the caller of this subroutine etc..  
  1044.  
  1045. \Xi{\kwd{defined(}<expr>\kwd{)}*}
  1046. Tests whether the lvalue <expr> has a real value.
  1047.  
  1048. \Xi{\kwd{dump} [<label>]}
  1049. Immediate core dump. When reincarnated, starts at <label>.
  1050.  
  1051. \Xi{\kwd{local(}<list>\kwd{)}}
  1052. Creates a scope for the listed variables local to the enclosing block,
  1053. subroutine or eval. 
  1054.  
  1055. \Xi{\kwd{package} <name>}
  1056. Designates the remainder of the current block as a package.
  1057.  
  1058. \Xi{\kwd{require(}\oEXPR\kwd{)}*}
  1059. Includes the specified file from the perl library. Does not include
  1060. more than once, and yields a fatal error if the file does include not OK. 
  1061.  
  1062. \Xi{\kwd{reset} [\kwd{(}<expr>\kwd{)}*]}
  1063. Resets |??| searches so that they work again. <expr> is a list of
  1064. single letters. All variables and arrays beginning with one of those
  1065. letters are reset to their pristine state.  Only affects the current
  1066. package.
  1067.  
  1068. \Xi{\kwd{scalar(}<expr>\kwd{)}}
  1069. Forces evaluation of <expr> in scalar context.
  1070.  
  1071. \Xi{\kwd{sub} <name> \{ <expr> |;| ... \}}
  1072. Designates <name> as a subroutine. Parameters are passed by reference
  1073. as array |@_|. Returns the value of the last expression evaluated. 
  1074.  
  1075. \Xi{\kwd{undef}[\kwd{(}<lvalue>\kwd{)}*]}
  1076. Undefines the <lvalue>. Always returns the undefined value.
  1077.  
  1078. \Xi{\kwd{wantarray}}
  1079. Returns true if the current context expects an array value.
  1080.  
  1081. \end{enum}
  1082. \section{Formats} 
  1083.  
  1084. \kwd{format} [<name>] |=| \\
  1085. <formlist> \\
  1086. |.|
  1087.  
  1088. <formlist> pictures the lines, and contains the arguments which will
  1089. give values to the fields in the lines. Picture fields are:
  1090.  
  1091. |  @<<<...  | left adjusted field, repeat the |<| to denote the desired
  1092. width; \\
  1093. |  @>>>...  | right adjusted field; \\
  1094. |  @|\|\|\||...  | centered field; \\
  1095. |  @#.##... | numeric format with implied decimal point; \\
  1096. |  @*       | a multi-line field.
  1097.  
  1098. Use \^ instead of |@| for multi-line block filling.
  1099.  
  1100. Use |~| at the beginning of a line to suppress unwanted empty lines.
  1101.  
  1102. Use |~~| at the beginning of a line to have this format line repeated
  1103. until all fields are exhausted. 
  1104.  
  1105. Use |$-| to zero to force a page break.
  1106.  
  1107. See also |$|\^, |$~|, |$-| and |$=| in section ``Special Variables''.
  1108. \section{Info from system files} 
  1109.  
  1110. {\xiipt\sl passwd} \\
  1111. Info is (\$name, \$passwd, \$uid, \$gid, \$quota, \$comment, \$gcos, \$dir, \$shell).
  1112.  
  1113. \begin{enum}{6cm}
  1114.  
  1115. \Xi{\kwd{endpwent}}    Ends lookup processing.
  1116.  
  1117. \Xi{\kwd{getpwent}}    Gets next info.
  1118.  
  1119. \Xi{\kwd{getpwnam(}<name>\kwd{)}}    Gets info by name. 
  1120.  
  1121. \Xi{\kwd{getpwuid(}<uid>\kwd{)}}    Gets info by uid.
  1122.  
  1123. \Xi{\kwd{setpwent}}    Resets lookup processing.
  1124.  
  1125. \end{enum}
  1126.  
  1127. {\vskip6pt\xiipt\sl group} \\
  1128. Info is a 4-item array: (\$name, \$passwd, \$gid, \$members).
  1129.  
  1130. \begin{enum}{6cm}
  1131.  
  1132. \Xi{\kwd{endgrent}}    Ends lookup processing.
  1133.  
  1134. \Xi{\kwd{getgrgid(}<gid>\kwd{)}}    Gets info by group id. 
  1135.  
  1136. \Xi{\kwd{getgrnam(}<name>\kwd{)}}    Gets info by name.
  1137.  
  1138. \Xi{\kwd{getgrent}}    Gets next info.
  1139.  
  1140. \Xi{\kwd{setgrent}}    Resets lookup processing.
  1141.  
  1142. \end{enum}
  1143.  
  1144. {\vskip6pt\xiipt\sl hosts} \\
  1145. Info is (\$name, \$aliases, \$addrtype, \$length, @addrs).
  1146.  
  1147. \begin{enum}{6cm}
  1148.  
  1149. \Xi{\kwd{endhostent}}    Ends lookup processing.
  1150.  
  1151. \Xi{\kwd{gethostbyname(}<name>\kwd{)}}    Gets info by name.
  1152.  
  1153. \Xi{\kwd{gethostent}}    Gets next info.
  1154.  
  1155. \Xi{\kwd{sethostent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1156.  
  1157. \end{enum}
  1158.  
  1159. {\vskip6pt\xiipt\sl networks} \\
  1160. Info is (\$name, \$aliases, \$addrtype, \$net).
  1161.  
  1162. \begin{enum}{6cm}
  1163.  
  1164. \Xi{\kwd{endnetent}}    Ends lookup processing.
  1165.  
  1166. \Xi{\kwd{getnetbyaddr(}<addr>\kwd{,}<type>\kwd{)}}    Gets info by address and type.
  1167.  
  1168. \Xi{\kwd{getnetbyname(}<name>\kwd{)}}    Gets info by name.
  1169.  
  1170. \Xi{\kwd{getnetent}}    Gets next info.
  1171.  
  1172. \Xi{\kwd{setnetent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1173.  
  1174. \end{enum}
  1175.  
  1176. {\vskip6pt\xiipt\sl services} \\
  1177. Info is (\$name, \$aliases, \$port, \$proto).
  1178.  
  1179. \begin{enum}{6cm}
  1180.  
  1181. \Xi{\kwd{endservent}}    Ends lookup processing.
  1182.  
  1183. \Xi{\kwd{getservbyname(}<name>\kwd{, }<proto>\kwd{)}}    Gets info by name. 
  1184.  
  1185. \Xi{\kwd{getservbyport(}<port>\kwd{, }<proto>\kwd{)}}    Gets info by port.
  1186.  
  1187. \Xi{\kwd{getservent}}    Gets next info.
  1188.  
  1189. \Xi{\kwd{setservent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1190.  
  1191. \end{enum}
  1192.  
  1193. {\vskip6pt\xiipt\sl protocols} \\
  1194.  
  1195. Info is (\$name, \$aliases, \$proto).
  1196.  
  1197. \begin{enum}{6cm}
  1198.  
  1199. \Xi{\kwd{endprotoent}}    Ends lookup processing.
  1200.  
  1201. \Xi{\kwd{getprotobyname(}<name>\kwd{)}}    Gets info by name.
  1202.  
  1203. \Xi{\kwd{getprotobynumber(}<number>\kwd{)}}    Gets info by number.
  1204.  
  1205. \Xi{\kwd{getprotoent}}    Gets next info.
  1206.  
  1207. \Xi{\kwd{setprotoent(}<stayopen>\kwd{)}}    Resets lookup processing.
  1208.  
  1209. \end{enum}
  1210. \section{Regular expressions} 
  1211.  
  1212. Each character matches itself, unless it is one of the special
  1213. characters |+?.*()[]{}|\||\|.
  1214.  
  1215. \begin{enum}{1cm}
  1216.  
  1217. \Xj{|.|}
  1218. matches an arbitrary character, but not a newline.
  1219.  
  1220. \Xj{|(|\ldots|)|}
  1221. groups a series of pattern elements to a single element.
  1222.  
  1223. \Xj{|+|}
  1224. matches the preceding pattern element one or more times.
  1225.  
  1226. \Xj{|?|}
  1227. matches zero or one times.
  1228.  
  1229. \Xj{|*|}
  1230. matches zero or more times.
  1231.  
  1232. \Xj{\{<n>|,|<m>\}}
  1233. denotes the minimum <n> and maximum <m> match count. |{|<n>|}| means
  1234. exactly <n> times; |{|<n>|,}| means at least <n> times. 
  1235.  
  1236. \Xj{|\char`\[|\ldots|\char`\]|}
  1237. denotes a class of characters to match. |[|\^\ldots|]| negates the class.
  1238.  
  1239. \Xj{|(|\ldots\|\ldots\|\ldots|)|}
  1240. matches one of the alternatives.
  1241.  
  1242. \end{enum}
  1243.  
  1244. Non-alphanumerics can be escaped from their special meaning using a
  1245. |\|.
  1246.  
  1247. \begin{enum}{1cm}
  1248.  
  1249. \Xj{|\char`\\w|}
  1250. matches alphanumeric, including ``|_|'', |\W| matches non-alphanumeric.
  1251.  
  1252. \Xj{|\char`\\b|}
  1253. matches word boundaries, |\B| matches non-boundaries.
  1254.  
  1255. \Xj{|\char`\\s|}
  1256. matches whitespace, |\S| matches non-whitespace.
  1257.  
  1258. \Xj{|\char`\\d|}
  1259. matches numeric, |\D| matches non-numeric.
  1260.  
  1261. \Xj{|\char`\\n|, |\char`\\r|, |\char`\\f|, |\char`\\t| etc.} 
  1262. have their usual meaning.
  1263.  
  1264. \Xj{|\char`\\w|, |\char`\\s| and |\char`\\d|}
  1265.  may be used within character classes, |\b| denotes backspace in this context.
  1266.  
  1267. \Xj{|\char`\\1|\ldots|\char`\\9|}
  1268. refer to matched sub-expressions, grouped with |()|, inside
  1269. the match. 
  1270.  
  1271. \Xj{|\char`\\10|}
  1272. and up can also be used if the pattern
  1273. matches that many sub-expressions. 
  1274.  
  1275. \end{enum}
  1276.  
  1277. See also |$1|\ldots|$9|, |$+|, |$&|, |$`| and |$'| in section ``Special
  1278. Variables''.
  1279.  
  1280. \section{Special variables} 
  1281.  
  1282. The following variables are global and should be localized in subroutines:
  1283.  
  1284. \begin{enum}{1cm}
  1285.  
  1286. \Xi{|\char`\$\char`\_|}
  1287. The default input and pattern-searching space.
  1288.  
  1289. \Xi{|\char`\$\char`\.|}
  1290. The current input line number of the last filehandle that was read.
  1291.  
  1292. \Xi{|\char`\$\char`\/|}
  1293. The input record separator, newline by default. May be multi-character.
  1294.  
  1295. \Xi{|\char`\$\char`\,|}
  1296. The output field separator for the print operator.
  1297.  
  1298. \Xi{|\char`\$\char`\"|}
  1299. The separator which joins elements of arrays interpolated in strings.
  1300.  
  1301. \Xi{|\char`\$\char`\\|}
  1302. The output record separator for the print operator.
  1303.  
  1304. \Xi{|\char`\$\char`\#|}
  1305. The output format for printed numbers. Initial value is ``|%.20g|''.
  1306.  
  1307. \Xi{|\char`\$\char`\*|}
  1308. Set to 1 to do multiline matching within a string, 0 to assume strings
  1309. contain a single line. Default is 0. 
  1310.  
  1311. \Xi{|\char`\$\char`\?|}
  1312. The status returned by the last |`|<command>|`|, pipe close or
  1313. \kwd{system} operator. 
  1314.  
  1315. \Xi{|\char`\$\char`\]|}
  1316. The perl version string (as displayed with |perl -v|), or version number.
  1317.  
  1318. \Xi{|\char`\$\char`\[|}
  1319. The index of the first element in an array, and of the first character
  1320. in a substring. Default is 0. 
  1321.  
  1322. \Xi{|\char`\$\char`\;|}
  1323. The subscript separator for multi-dimensional array emulation. Default
  1324. is |"\034"|. 
  1325.  
  1326. \Xi{|\char`\$\char`\!|}
  1327. If used in a numeric context, yields the current value of errno. If
  1328. used in a string context, yields the corresponding error string. 
  1329.  
  1330. \Xi{|\char`\$\char`\@|}
  1331. The perl error message from the last eval or \kwd{do} <expr> command.
  1332.  
  1333. \Xi{|\char`\$\char`\:|}
  1334. The set of characters after which a string may be broken to fill
  1335. continuation fields (starting with ``|^|'') in a format. 
  1336.  
  1337. \Xi{|\char`\$\char`\0|}
  1338. The name of the file containing the perl script being executed. May be
  1339. assigned to. 
  1340.  
  1341. \Xi{|\char`\$\char`\$|}
  1342. The process number of the perl running this script. Altered (in the
  1343. child process) by \kwd{fork}. 
  1344.  
  1345. \Xi{|\char`\$\char`\<|}
  1346. The real uid of this process.
  1347.  
  1348. \Xi{|\char`\$\char`\>|}
  1349. The effective uid of this process. 
  1350.  
  1351. \Xi{|\char`\$\char`\(|}
  1352. The real gid of this process.
  1353.  
  1354. \Xi{|\char`\$\char`\)|}
  1355. The effective gid of this process.
  1356.  
  1357. \Xi{|\char`\$\char`\^D|}
  1358. The debug flags as passed to perl using |-D| .
  1359.  
  1360. \Xi{|\char`\$\char`\^F|}
  1361. The highest system file descriptor, ordinarily 2.
  1362.  
  1363. \Xi{|\char`\${\char`\^}I|}
  1364. In-place edit extension as passed to perl using |-i| .
  1365.  
  1366. \Xi{|\char`\$\char`\^P|}
  1367. Internal debugging flag.
  1368.  
  1369. \Xi{|\char`\$\char`\^T|}
  1370. The time (as delivered by \kwd{time}) when the program started. This
  1371. value is used by the file test operators ``|-M|'', ``|-A|'' and
  1372. ``|-C|''.
  1373.  
  1374. \Xi{|\char`\$\char`\^W|}
  1375. The value if the |-w| option as passed to perl.
  1376.  
  1377. \Xi{|\char`\$\char`\^X|}
  1378. The name by which this perl was invoked.
  1379.  
  1380. \end{enum}
  1381.  
  1382. The following variables are context dependent and need not be
  1383. localized:
  1384.  
  1385. \begin{enum}{1cm}
  1386.  
  1387. \Xi{|\char`\$\char`\%|}
  1388. The current page number of the currently selected output channel.
  1389.  
  1390. \Xi{|\char`\$\char`\=|}
  1391. The page length of the current output channel. Default is 60 lines.
  1392.  
  1393. \Xi{|\char`\$\char`\-|}
  1394. The number of lines left on the page.
  1395.  
  1396. \Xi{|\char`\$\char`\~|}
  1397. The name of the current report format.
  1398.  
  1399. \Xi{|\char`\$\char`\^|}
  1400. The name of the current top-of-page format.
  1401.  
  1402. \Xi{|\char`\$\char`\||}
  1403. If set to nonzero, forces a flush after every write or print on the
  1404. currently selected output channel. Default is 0. 
  1405.  
  1406. \Xi{|\char`\$ARGV|}
  1407. The name of the current file when reading from |<>| .
  1408. \end{enum}
  1409.  
  1410. The following variables are always local to the current block:
  1411.  
  1412. \begin{enum}{1cm}
  1413.  
  1414. \Xi{|\char`\$\char`\&|}
  1415. The string matched by the last pattern match.
  1416.  
  1417. \Xi{|\char`\$\char`\`|}
  1418. The string preceding what was matched by the last pattern match.
  1419.  
  1420. \Xi{|\char`\$\char`\'|}
  1421. The string following what was matched by the last pattern match. 
  1422.  
  1423. \Xi{|\char`\$\char`\+|}
  1424. The last bracket matched by the last search pattern.
  1425.  
  1426. \Xi{\$|1|\ldots\$|9|\ldots}
  1427. Contains the subpattern from the corresponding set of parentheses in
  1428. the last pattern matched. |$10|\ldots and up are only available if the
  1429. match contained that many sub-expressions. 
  1430.  
  1431. \end{enum}
  1432.  
  1433.  
  1434. \section{Special arrays} 
  1435.  
  1436. \begin{enum}{1.5cm}
  1437.  
  1438. \Xi{|@ARGV|}
  1439. Contains the command line arguments for the script (not including the command name).
  1440.  
  1441. \Xi{|@INC|}
  1442. Contains the list of places to look for perl scripts to be evaluated
  1443. by the \kwd{do} <filename> and \kwd{require} commands. 
  1444.  
  1445. \Xi{|@\char`\_|}
  1446. Parameter array for subroutines. Also used by \kwd{split} if not in
  1447. array context. 
  1448.  
  1449. \Xi{|\char`\%ENV|}
  1450. Contains the current environment.
  1451.  
  1452. \Xi{|\char`\%INC|}
  1453. List of files that have been \kwd{require}d or \kwd{do}ne.
  1454.  
  1455. \Xi{|\char`\%SIG|}Used to set signal handlers for various signals.
  1456.  
  1457. \end{enum}
  1458. \section{The perl debugger} 
  1459.  
  1460. The perl symbolic debugger is invoked with |perl -d|.
  1461.  
  1462. \begin{enum}{2.5cm}
  1463.  
  1464. \Xi{|h|}
  1465. Prints out a help message.
  1466.  
  1467. \Xi{|T|}
  1468. Stack trace.
  1469.  
  1470. \Xi{|s|}
  1471. Single steps.
  1472.  
  1473. \Xi{|n|}
  1474. Single steps around subroutine call.
  1475.  
  1476. \Xi{|r|}
  1477. Returns from the current subroutine.
  1478.  
  1479. \Xi{|c| [<line>]}
  1480. Continues (until <line>, or another breakpoint or exit).
  1481.  
  1482. \Xi{\fbox{<ret>}}
  1483. Repeats last |s| or |n|.
  1484.  
  1485. \Xi{|l| [<range>]}
  1486. Lists a range of lines. <range> may be a number, start-end,
  1487. start+amount, or a subroutine name. If omitted, lists next window. 
  1488.  
  1489. \Xi{|f| <file>}
  1490. Switches to <file> and start listing it.
  1491.  
  1492. \Xi{|-|}
  1493. Lists previous window.
  1494.  
  1495. \Xi{|w|}
  1496. Lists window around current line.
  1497.  
  1498. \Xi{|l| <sub>}
  1499. Lists the named <sub>routine.
  1500.  
  1501. \Xi{|/|<pattern>|/|}
  1502. Forward search for <pattern>.
  1503.  
  1504. \Xi{|?|<pattern>|?|}
  1505. Backward search for <pattern>.
  1506.  
  1507. \Xi{|L|}
  1508. Lists lines that have breakpoints or actions.
  1509.  
  1510. \Xi{|S|}
  1511. List the names of all subroutines.
  1512.  
  1513. \Xi{|t|}
  1514. Toggles trace mode.
  1515.  
  1516. \Xi{|b| [<line> [<condition>]]}
  1517. Sets breakpoint at <line>, default: current line.
  1518.  
  1519. \Xi{|b| <subname> [<condition>]}
  1520. Sets breakpoint at the subroutine.
  1521.  
  1522. \Xi{|S|}
  1523. Lists names of all subroutines.
  1524.  
  1525. \Xi{|d| [<line>]}
  1526. Deletes breakpoint at the given line.
  1527.  
  1528. \Xi{|D|}
  1529. Deletes all breakpoints.
  1530.  
  1531. \Xi{|a| <line command>}
  1532. Sets an action for line.
  1533.  
  1534. \Xi{|A|}
  1535. Deletes all line actions.
  1536.  
  1537. \Xi{|\char`\<| <command>}
  1538. Sets an action to be executed before every debugger prompt.
  1539.  
  1540. \Xi{|\char`\>| <command>}
  1541. Sets an action to be executed before every |s|, |c| or |n| command.
  1542.  
  1543. \Xi{|V| [<package> [<vars>] ]}
  1544. Lists all variables in a package. Default package is main.
  1545.  
  1546. \Xi{|X| [<vars>]}
  1547. Like |V|, but assumes current package.
  1548.  
  1549. \Xi{|!| [ [-]<number>]}
  1550. Redo a debugging command. Default is previous command.
  1551.  
  1552. \Xi{|H| [-<number>]}
  1553. Displays the last -<number> commands of more than one letter.
  1554.  
  1555. \Xi{|q|}
  1556. Quits. You may also use your \fbox{<eof>} character.
  1557.  
  1558. \Xi{<command>}
  1559. Executes <command> as a perl statement.
  1560.  
  1561. \Xi{|p| \oEXPR}
  1562. Prints <expr>.
  1563.  
  1564. \Xi{|=|< >[<alias value>]}
  1565. Sets alias, or lists current aliases.
  1566.  
  1567. \end{enum}
  1568. \newpage
  1569. \vfill \vfill \vfill
  1570. \makebox[\textwidth]{Perl Reference Guide Revision \perlrev \hfill
  1571. \copyright 1989,1990,1991 Johan Vromans}
  1572.  
  1573. \end{document}
  1574.